﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace BusStation
{
    class BusStation
    {
        static StringBuilder output = new StringBuilder();
        static void Main(string[] args)
        {
            //TestGenerator.CreateTest("test10.in.txt");
            //ReadInput(@"..\..\Tests\test10.in.txt");
            //PrintOutput(@"..\..\Tests\test10.out.txt");
            ReadInput();
            PrintOutput();
        }

        private static void ReadInput()
        {
            TimeInterval searchingTimeInterval = new TimeInterval(Console.ReadLine());
            List<TimeInterval> busIntervals = PrepareInputSequence(Console.ReadLine());
            FindAllBus(searchingTimeInterval, busIntervals);
        }

        private static void ReadInput(string fileName)
        {
            StreamReader reader = new StreamReader(fileName);
            using (reader)
            {
                TimeInterval searchingTimeInterval = new TimeInterval(reader.ReadLine());
                List<TimeInterval> busIntervals = PrepareInputSequence(reader.ReadLine());
                FindAllBus(searchingTimeInterval, busIntervals);
            }
        }

        private static List<TimeInterval> PrepareInputSequence(string inputLine)
        {
            string[] stringSequence = inputLine.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            List<TimeInterval> busIntervals = new List<TimeInterval>();
            foreach (var item in stringSequence)
            {
                busIntervals.Add(new TimeInterval(item));
            }
            return busIntervals;
        }

        private static void FindAllBus(TimeInterval searchingTimeInterval, List<TimeInterval> busIntervals)
        {
            HashSet<TimeInterval> arriveAfter = new HashSet<TimeInterval>();
            HashSet<TimeInterval> leaveBefore = new HashSet<TimeInterval>();

            foreach (TimeInterval bus in busIntervals)
            {
                if (bus.ArriveTime >= searchingTimeInterval.ArriveTime)
                {
                    arriveAfter.Add(bus);
                }
                if (bus.LeaveTime <= searchingTimeInterval.LeaveTime)
                {
                    leaveBefore.Add(bus);
                }
            }

            IEnumerable<TimeInterval> searchedBus = arriveAfter.Intersect(leaveBefore);
            foreach (TimeInterval bus in searchedBus)
            {
                output.Append("[" + bus.ArriveTime.Hours.ToString().PadLeft(2, '0') + ":" + bus.ArriveTime.Minutes.ToString().PadLeft(2, '0'));
                output.Append("-" + bus.LeaveTime.Hours.ToString().PadLeft(2, '0') + ":" + bus.LeaveTime.Minutes.ToString().PadLeft(2, '0') + "]");
                output.Append(",");
            }
        }

        private static void PrintOutput()
        {
            if (output.Length > 1)
            {
                Console.WriteLine(output.ToString().Remove(output.Length - 1, 1));
            }
            else
            {
                output.AppendLine("-1");
                Console.WriteLine(output);
            }
        }

        private static void PrintOutput(string fileName)
        {
            StreamWriter writer = new StreamWriter(fileName);
            using (writer)
            {
                if (output.Length > 1)
                {
                    writer.Write(output.ToString().Remove(output.Length - 1, 1));
                }
                else
                {
                    output.AppendLine("-1");
                    writer.Write(output);
                }
            }
        }

    }
}
